package com.letao.server.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.letao.server.dto.AdminFormDTO;
import com.letao.server.dto.Result;
import com.letao.server.service.IAdminService;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

import static com.letao.server.constants.RedisConstants.ADMIN_AUTH_KEY;

@Service
public class AdminServiceImpl implements IAdminService {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public Result login(AdminFormDTO form) {
        if (!"admin".equals(form.getAccount()) || !"123456".equals(form.getPassword())) {
            return Result.fail("警报!");
        }
        String s = RandomUtil.randomString(20);
        stringRedisTemplate.opsForValue().set(ADMIN_AUTH_KEY, s, 5, TimeUnit.MINUTES);
        return Result.success(s);
    }
}
